package com.tz.fruit.controller.backstage;


import com.tz.fruit.entity.PageBean;
import com.tz.fruit.entity.User;
import com.tz.fruit.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


import org.springframework.stereotype.Controller;



import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2017/7/21.
 */
@Controller(value = "backUserController")
@RequestMapping("/backstage/user")
public class UserController {

    @Autowired
     private IUserService userService;
    @RequestMapping("/list")
    public String list(Model model, String username, @RequestParam(defaultValue = "1") Long pageNow) {
        //获取PageBean<User>对象
        PageBean<User> pageBean=userService.findByPage(username,pageNow,4L);
        System.out.println("pageBean:"+pageBean);
        System.out.println("username:"+username);
       //放入到request作用域中
        model.addAttribute("pageBean", pageBean);
        model.addAttribute("username",username==null?"":username);

        return "backstage/user/list";
    }

    @RequestMapping("/login")
    public String login(){
        return "/backstage/user/login";
    }

    @RequestMapping("/loginVali")
    public String loginVali(User user){
        //to do...
        return "/backstage/index";
    }

    @RequestMapping("/safeExit")
    public String safeExit(HttpSession session){
        //清空session
        session.invalidate();
        //重定向到登录界面
        return "redirect:login";
    }

    @RequestMapping("/updatePwdView")
    public String updatePwdView(Long userId){
        //to do...
        return "/backstage/user/updatePwdView";
    }

}
